import { ksort } from "locutus/php/array/index"
import { md5 } from "locutus/php/strings/index"
import app from "../config/app"

function buildQuery(params)
{
  var esc = encodeURIComponent;
  var query = Object.keys(params)
                    .map(k => esc(k) + '=' + esc(params[k]))
                    .join('&');
  return query;
}

function getSign(params) {

    params.time = Date.parse(new Date()) / 1000 ;
    params.nonce  = '';
    params.version  = app.version;

    ksort(params);

    var str = '';
    for (var key in params){
        str += key + '=' + params[key] + '|'
    }

    str += app.secret_key;
    return md5(str);
}

export {
    getSign,
    buildQuery
}